package com.simple.simple_view.config.mq;

import com.simple.simple_view.domain.system.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 *@description: MQ配置
 *@author: hisen
 *@Time: 2023/10/30  0:21
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    /**
     * 定义交换机
     */
    @Bean(RabbitMQConstant.EXCHANGE_TOPIC)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(RabbitMQConstant.EXCHANGE_TOPIC).durable(true).build();
    }

    /**
     * 定义视频点赞队列
     */
    @Bean(RabbitMQConstant.QUEUE_VIDEO_FAVORITE)
    public Queue queueVideo(){
        return new Queue(RabbitMQConstant.QUEUE_VIDEO_FAVORITE,true);
    }

    /**
     * 将视频点赞队列绑定到交换机
     */
    @Bean
    public Binding bindingVideo(@Qualifier(RabbitMQConstant.QUEUE_VIDEO_FAVORITE) Queue videoQueue, @Qualifier(RabbitMQConstant.EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(videoQueue).to(exchange).with(RabbitMQConstant.KEY_VIDEO).noargs();
    }

    /**
     * 评论队列
     * @return
     */
    @Bean(RabbitMQConstant.QUEUE_COMMENT)
    public Queue queueComment(){return new Queue(RabbitMQConstant.QUEUE_COMMENT);}

}